var e = this, p = {storeID: app.globalData.VendorInfo.Id, userName: app.globalData.Userinfo.UserName};
$.xsr(cartapi.GetCartList, p, function (t) {

    var n = {
        userAccount: app.globalData.Userinfo.UserName,
        ShoppingCartList: [],
        couponItemId: e.data.couponItemId,
        IsUseCoupon: e.data.IsUseCoupon,
        isFightGroup: $.isNull(e.data.spinfo) ? "" : JSON.parse(e.data.spinfo).isFightGroup,
        addressId: e.data.addressid || 0,
        physicalStoreId: e.data.physicalStoreId,
        marktingEventId: e.data.marktingEventId,
        sponsorId: e.data.sponsorId
    };
    if ($.isNull(e.data.spinfo)) {
        var r = t.Info.VendorList[0].ShoppingCartList;
        for (var i in r) r[i].IsCheck && (r[i].AddTime = e.getLocalTime(r[i].AddTime), n.ShoppingCartList.push(r[i]))
    } else n.ShoppingCartList.push(JSON.parse(e.data.spinfo));

    e.setData({cartinfo: n.ShoppingCartList})

    $.xsr(cartapi.GoSettlement, n, function (t) {
        console.log(t);
        if (t.Code == 0) {
            var n = new Date, r = new Date(n);
            r.setDate(n.getDate() + parseInt(t.Info.ShoppingCartHeaderInfo.ReservationDateSpan));
            var i = n.getFullYear() + "-" + (n.getMonth() + 1) + "-" + n.getDate(),
                s = r.getFullYear() + "-" + (r.getMonth() + 1) + "-" + r.getDate();
            e.setData({
                addressid: $.isNull(t.Info.DeliveryAddress) ? 0 : t.Info.DeliveryAddress.id,
                submitinfo: t.Info,
                stdate: i,
                eddate: s
            }),
                $.isNull(t.Info.VendorShoppingCartItemsList[0].ShoppingCartList[0].speStr) ? e.setData({specification: !0}) : e.setData({specification: !1}), t.Info.UserMembership.PointAsCashRate == 0 ? e.setData({disbursements: t.Info.ShoppingCartHeaderInfo.ActualPayPrice}) : e.setData({disbursements: (t.Info.ShoppingCartHeaderInfo.ActualPayPrice - e.data.integral / t.Info.UserMembership.PointAsCashRate).toFixed(2)}), e.data.disbursements < 0 && e.setData({disbursements: 0}), $.isNull(e.data.submitinfo.ShoppingCartUsedCouponInfo) || e.setData({couponItemId: e.data.submitinfo.ShoppingCartUsedCouponInfo.CouponItem.Id}), t.Info.ShoppingCartHeaderInfo.MaxUsableCash >= e.data.disbursements ? e.setData({
                balance: e.data.disbursements,
                realMoney: 0
            }) : e.setData({
                balance: t.Info.ShoppingCartHeaderInfo.MaxUsableCash,
                realMoney: (e.data.disbursements - e.data.submitinfo.ShoppingCartHeaderInfo.MaxUsableCash).toFixed(2)
            })
        }
    })
})